package com.itheima.util;

import java.util.ArrayList;
import java.util.Random;

public class CodeUtil {
    //生成验证码
    public static String getCode() {
        ArrayList<Character> letter = new ArrayList<>();

        for (int i = 0; i < 26; i++) {
            letter.add((char) (65 + i));
            letter.add((char) (97 + i));
        }

        //随机去六个字母
        Random random = new Random();
        ArrayList<Character> before = new ArrayList<>();
        StringBuilder result = new StringBuilder();
        for (int i = 0; i < 4; i++) {
            int index = random.nextInt(letter.toArray().length);
            result.append(letter.get(index));
        }

        //随机一个数字
        int number = random.nextInt(9);

        //随机数字的索引
        int numberIndex = random.nextInt(5);
        result.insert(numberIndex, number);
        return result.toString();
    }
}
